import ar from 'element-ui/src/locale/lang/ar'

export function transfromTreeData(treeData, subArray, parentArray) {
  for (let i = 0; i < treeData.length; i++) {
    let array = []
    array = subArray.concat(array)
    array.push(treeData[i].id)
    if (treeData[i].children && treeData[i].children.length > 0) {
      transfromTreeData(treeData[i].children, array, parentArray)
    } else if (treeData[i].mark && treeData[i].mark != 'false') {
      parentArray.push(array)
    }
  }
}

export function getIdsFromTreeData(id, treeData, array) {
  for (let i = 0; i < treeData.length; i++) {
    if (treeData[i].children && treeData[i].children.length > 0) {
      array.push(treeData[i].id)
      if (!getIdsFromTreeData(id, treeData[i].children, array)) {
        array.splice(array.length - 1, 1)
        continue
      } else {
        return true
      }
    } else {
      if (treeData[i].id == id) {
        array.push(treeData[i].id)
        return true
      } else {
        continue
      }
    }
  }
}

export function setTreeDisable(id, treeData, disabled) {
  for (let i = 0; i < treeData.length; i++) {
    if (treeData[i].id == id) {
      treeData[i].disabled = disabled
      return true
    } else {
      if (treeData[i].children && treeData[i].children.length > 0) {
        if (setTreeDisable(id, treeData[i].children, disabled)) {
          return true
        }
      }
    }
  }
  return false
}
